# plugs/code.py
#
#

""" code related commands """

__copyright__ = 'this file is in the public domain'

from gozerbot.commands import cmnds
from gozerbot.examples import examples
import os

def handle_codestat(bot, ievent):
    """ code-stat .. show some stats of the code """
    lines = 0
    words = 0
    chars = 0
    files = 0
    for i in ('files', 'tests', 'web', 'plugs', 'dbplugs', 'gozerbot'):
        for j in os.listdir(i):
            if j.endswith('.py'):
                pyfile = open(i + '/' + j, 'r')
                files += 1
                for z in pyfile:
                    z = z.strip()
                    if z:
                        lines += 1
                        chars += len(z)
                        words += len(z.split()) 
                pyfile.close()
    ievent.reply('files: %s lines: %s words: %s chars: %s' % (files, \
lines, words, chars))

cmnds.add('code-stat', handle_codestat, 'USER')
examples.add('code-stat', 'show some code stats', 'code-stat')
